﻿// SMIL is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://smil.codeplex.com/



using System;
using System.Collections.Generic;
using Microsoft.SharePoint;
using SMIL.Server.SPGeoRssCommonTypes;

namespace SMIL.Server.SPGeoRssCore
{
    public abstract class SPGeoRssBase : SPGeoRssCommonTypes.ISPGeoRss
    {
        public SPWeb SPWeb { get; set; }
        public SPList SPList { get; set; }
        public SPView SPView { get; set; }

        public virtual LayersResponse GetLayerList(LayersRequest layersRequest)
        {
            SPWeb = new SPSite(layersRequest.SiteUrl).OpenWeb();
            return SPGeoRssCore.GetLayerList(SPWeb);
        }

        public virtual GeoRss GetGeoRssForLayer(LayerRequest layerRequest)
        {
            
            SPWeb = new SPSite(layerRequest.SiteUrl).OpenWeb();
            SPList = SPWeb.Lists[layerRequest.SPListName];
            if (!string.IsNullOrEmpty(layerRequest.SPViewName))
                SPView = SPList.Views[layerRequest.SPViewName];

            return SPGeoRssCore.GenerateGeoRSS(SPWeb, SPList, SPView,
                SPGeoRssCore.GetRequestPort(layerRequest.SiteUrl)
                );
        }

        public virtual ItemDetailResponse GetSPItemDetail(ItemDetailRequest itemDetailRequest)
        {
            SPWeb = new SPSite(itemDetailRequest.SiteUrl).OpenWeb();
            SPList = SPWeb.Lists[itemDetailRequest.SPListname];
            if (itemDetailRequest.SPViewName != null)
                SPView = SPList.Views[itemDetailRequest.SPViewName];

            return SPGeoRssCore.GenerateItemDetails(SPWeb, SPList, SPView, itemDetailRequest.SPItemGuid.ToString());
        }


        public System.Xml.XmlDocument GetLayer(LayerRequest layerRequest)
        {
            throw new NotImplementedException();
        }
    }

    
}
